﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace TanHuan.Authorize.Common
{ 
    public class DataAccessBase
    {
        public static string ConnStr = System.Configuration.ConfigurationManager.ConnectionStrings["AuthorizeDBStr"].ToString();

        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <param name="pItem"></param>
        /// <returns></returns>
        public DataTable GetPageList(PageItem pItem)
        {
            string sql = "PageList";
            DataTable table = new DataTable();
            using (SqlConnection conn = new SqlConnection(ConnStr))
            {
                SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);
                adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@PK", pItem.PK));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@SqlStr", pItem.SqlStr));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@Sort", pItem.Sort));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@Order", pItem.Order));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@Index", pItem.Index));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@Size", pItem.Size));
                adapter.SelectCommand.Parameters.Add(new SqlParameter("@Count", pItem.Count));
                adapter.SelectCommand.Parameters["@Count"].Direction = ParameterDirection.Output;
                adapter.Fill(table);
                pItem.Count = Convert.ToInt32(adapter.SelectCommand.Parameters["@Count"].Value);
                return table;
            } 
        }
    }
}
